﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Back.Xinkui.Entity.Company;
using Back.Xinkui.Common;
using Back.Xinkui.DataAccess.Company;
using CommonFramework.Utility;
public partial class company_productlist : System.Web.UI.Page
{

    protected List<ProdcutEntity> ProdcutList
    { get; set; }

    protected int CompanyId
    {
        get
        {
            return WebHelper.GetQueryStringValue<int>("companyId", 0);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AspNetPager1.PageSize = ddlPageCount.SelectedValue.ToType<int>(10);
            BindProductList();
        }
    }

    protected void BindProductList()
    {
        string where = " AND P.IsDeleted = 0";

        if (!string.IsNullOrEmpty(this.txtProductName.Text))
        {
            where += " AND P.ProductName Like '%" + this.txtProductName.Text.Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(this.ddpStatus.SelectedValue))
        {
            where += " AND P.AuditStatus = " + this.ddpStatus.SelectedValue;
        }
        if (CompanyId > 0)
        {
            where += " AND P.CompanyID = " + CompanyId;
        }

        Pager page = new Pager { PageIndex = AspNetPager1.CurrentPageIndex, PageSize = AspNetPager1.PageSize };

        ProdcutList = CompanyDataAccess.GetProductList(where, page);

        AspNetPager1.RecordCount = page.TotalCount;
    }

    protected void btnSerach_Click(object sender, EventArgs e)
    {
        BindProductList();
    }

    /// <summary>
    /// 翻页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindProductList();
    }
    /// <summary>
    /// 切换每页显示数据行数
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlPageCount_SelectedIndexChanged(object sender, EventArgs e)
    {
        AspNetPager1.PageSize = Convert.ToInt32(ddlPageCount.SelectedValue);
        BindProductList();
    }
}